﻿@using ERP.WebUI
@model RoleSelectedPermissionModel
@{
    int sortOrder = 1;
}
<div class="scrollx">
    <table class="permission-tbl table table-bordered data-table dataTables_wrapper">
    <thead>
        <tr>
            <th width="10%">序号</th>
            <th width="20%">模块(菜单)名称</th>
            <th width="12%">
                <input type="checkbox" onclick="CheckAllPermission(this.checked)" />
            </th>
            @foreach (var permission in Model.HeaderPermissionList)
            {
                <th>@permission.PermissionName</th>
            }
        </tr>
    </thead>
    <tbody>
        @foreach (var modulePermissionData in Model.ModulePermissionDataList)
        {
            <tr>
                <td>@(sortOrder++)</td>
                @if (modulePermissionData.ParentId != null)
                {
                    <td style="text-align: right;">[ @modulePermissionData.ModuleName ]</td>
                }
                else
                {
                    <td>@modulePermissionData.ModuleName</td>
                }
                <td width="12%">
                    @if (modulePermissionData.ParentId != null)
                    {
                        @Html.CheckBox("modulectx", modulePermissionData.Selected, new { @class = "parentpermissioncheck-" + modulePermissionData.ModuleId + " module-" + modulePermissionData.ParentId + " permission-" + modulePermissionData.ModuleId, @value = modulePermissionData.ModuleId, onclick = "CheckParentPermission(this.checked, " + modulePermissionData.ModuleId + ", " + modulePermissionData.ParentId + ")" })
                    }
                    else
                    {
                        @Html.CheckBox("modulectx", modulePermissionData.Selected, new { @class = "parentallpermissioncheck-" + modulePermissionData.ModuleId + " module-" + modulePermissionData.ModuleId + " permission-" + modulePermissionData.ModuleId, @value = modulePermissionData.ModuleId, onclick = "CheckParentModulePermission(this.checked, " + modulePermissionData.ModuleId + ")" })
                    }
                </td>
                @if (modulePermissionData.ParentId != null)
                {
                    foreach (var item in modulePermissionData.PermissionDataList)
                    {
                    <td>
                        @if (item.Enabled)
                        {
                            @Html.CheckBox("permissioncheck", item.Selected, new { @class = "childpermissioncheck-" + @modulePermissionData.ModuleId + " module-" + modulePermissionData.ParentId + " permission-" + modulePermissionData.ModuleId, @value = item.PermissionId, onclick = "CheckChildPermission(" + modulePermissionData.ModuleId + ", " + modulePermissionData.ParentId + ")" })
                        }
                    </td>
                    }
                }
                else
                {
                    for (int i = 0; i < Model.HeaderPermissionList.Count; i++)
                    {
                    <td></td>
                    }
                }
            </tr>
        }
    </tbody>
</table>
</div>
@Html.ScriptBlock(
    @<script type="text/javascript">
         $(function () {
             //Permission Table
             //$(".permission-tbl").dataTable({
             //    "bJQueryUI": false,
             //    "bFilter": false,
             //    "bInfo": false,
             //    'bPaginate': false,
             //    "sScrollY": "350px",
             //    "bScrollCollapse": true,
             //    "bAutoWidth": true,
             //});
         })
    </script>)